<template>
  <div class="home-container">
    <!-- 顶部横幅 -->
    <section class="hero-section">
      <div class="hero-content">
        <h1 class="hero-title">QPixel</h1>
        <p class="hero-subtitle">UE像素流管理平台</p>
        <el-button type="primary" size="large" @click="scrollToFeatures"
          >了解更多</el-button
        >
      </div>
    </section>

    <!-- 功能概览 -->
    <section ref="featuresSection" class="features-section">
      <h2 class="section-title">平台功能</h2>
      <div class="features-grid">
        <div
          v-for="(feature, index) in features"
          :key="index"
          class="feature-card"
          :class="{ visible: isVisible }"
          :style="{ transitionDelay: `${index * 0.05}s` }"
        >
          <div class="feature-icon">
            <el-icon :size="40">
              <component :is="feature.icon"></component>
            </el-icon>
          </div>
          <h3 class="feature-title">{{ feature.title }}</h3>
          <p class="feature-description">{{ feature.description }}</p>
          <router-link :to="feature.link" class="feature-link">
            <el-button type="primary">查看详情</el-button>
          </router-link>
        </div>
      </div>
    </section>

    <!-- 平台优势 -->
    <section class="benefits-section">
      <h2 class="section-title">平台优势</h2>
      <div class="benefits-grid">
        <div
          v-for="(benefit, index) in benefits"
          :key="index"
          class="benefit-card"
          :class="{ visible: isVisible }"
          :style="{ transitionDelay: `${index * 0.05}s` }"
        >
          <div class="benefit-image">
            <img :src="benefit.image" :alt="benefit.title" />
          </div>
          <div class="benefit-content">
            <h3 class="benefit-title">{{ benefit.title }}</h3>
            <p class="benefit-description">{{ benefit.description }}</p>
          </div>
        </div>
      </div>
    </section>

    <!-- 项目进展 -->
    <section class="progress-section">
      <h2 class="section-title">项目进展</h2>
      <div class="version-info">
        <div class="version-badge">v1.0.0</div>
        <h3 class="version-title">已完成核心功能</h3>
      </div>
      <div class="timeline">
        <div
          v-for="(milestone, index) in milestones"
          :key="index"
          class="milestone-item"
          :class="{ visible: isVisible, completed: milestone.completed }"
          :style="{ transitionDelay: `${index * 0.05}s` }"
        >
          <div class="milestone-dot"></div>
          <div class="milestone-content">
            <h3 class="milestone-title">{{ milestone.title }}</h3>
            <p class="milestone-description">{{ milestone.description }}</p>
            <div class="milestone-date">{{ milestone.date }}</div>
          </div>
        </div>
      </div>
      <div class="cta-container">
        <router-link to="/system-status">
          <el-button type="primary" size="large">开始使用</el-button>
        </router-link>
      </div>
    </section>
  </div>
</template>

<script setup>
import { ref, onMounted, onUnmounted } from "vue";
import { Monitor, Cpu, Folder, Document, Aim } from "@element-plus/icons-vue";

// 功能列表
const features = [
  {
    title: "系统监控",
    description: "实时监控服务器CPU、内存和GPU资源使用情况，确保系统稳定运行。",
    icon: Monitor,
    link: "/system-status",
  },
  {
    title: "UE工程管理",
    description: "高效管理UE工程文件，支持上传、下载、版本控制等功能。",
    icon: Folder,
    link: "/project-management",
  },
  {
    title: "像素实例管理",
    description: "一键部署和管理UE像素流实例，支持多实例并行运行。",
    icon: Cpu,
    link: "/instance-management",
  },
  {
    title: "API文档",
    description: "完整的API接口文档，方便开发者集成和扩展平台功能。",
    icon: Document,
    link: "/api-docs",
  },
  {
    title: "实例测试",
    description: "提供实例测试环境，验证像素流实例的性能和稳定性。",
    icon: Aim,
    link: "/instance-demo",
  },
];

// 平台优势
const benefits = [
  {
    title: "高效管理",
    description: "集中化管理UE像素流实例，提高工作效率，减少重复操作，让您的团队专注于创造性工作。",
    image: "https://images.unsplash.com/photo-1551288049-bebda4e38f71?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=80"
  },
  {
    title: "资源优化",
    description: "智能分配系统资源，最大化硬件性能，降低运营成本，提高资源利用率。",
    image: "https://images.unsplash.com/photo-1551434678-e076c223a692?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=80"
  },
  {
    title: "简化部署",
    description: "一键部署UE像素流实例，无需复杂配置，降低技术门槛，加速项目上线。",
    image: "https://images.unsplash.com/photo-1460925895917-afdab827c52f?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=80"
  },
  {
    title: "实时监控",
    description: "实时监控系统状态，及时发现并解决问题，确保服务稳定运行，提高用户体验。",
    image: "https://images.unsplash.com/photo-1504868584819-f8e8b4b6d7e3?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=80"
  },
];

// 项目里程碑
const milestones = [
  {
    title: "基础框架搭建",
    description: "完成项目基础结构和文档创建，配置MongoDB连接，初始化前后端项目。",
    date: "2024-08-21",
    completed: true
  },
  {
    title: "系统监控功能",
    description: "添加后端系统性能监控API，获取内存和显卡信息，创建监控模块和路由。",
    date: "2024-08-22",
    completed: true
  },
  {
    title: "UE工程管理",
    description: "实现UE工程文件的上传、下载和版本控制功能。",
    date: "2024-08-25",
    completed: true
  },
  {
    title: "像素实例管理",
    description: "完成UE像素实例的创建、启动、停止和监控功能。",
    date: "2024-08-28",
    completed: true
  },
  {
    title: "API文档与测试",
    description: "完成API文档编写和实例测试功能，发布v1.0.0版本。",
    date: "2024-08-30",
    completed: true
  },
];

// 滚动动效相关
const featuresSection = ref(null);
const isVisible = ref(false);
let observer = null;

// 滚动到功能区域
const scrollToFeatures = () => {
  featuresSection.value.scrollIntoView({ behavior: "smooth" });
};

// 监听元素可见性
const setupIntersectionObserver = () => {
  observer = new IntersectionObserver(
    (entries) => {
      entries.forEach((entry) => {
        if (entry.isIntersecting) {
          isVisible.value = true;
        }
      });
    },
    { threshold: 0.1 }
  );

  // 监听所有需要动效的区域
  document
    .querySelectorAll(".features-grid, .benefits-grid, .timeline")
    .forEach((el) => {
      observer.observe(el);
    });
};

onMounted(() => {
  setupIntersectionObserver();
});

onUnmounted(() => {
  if (observer) {
    observer.disconnect();
  }
});
</script>

<style scoped>
/* 主容器样式 */
.home-container {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
}

/* 顶部横幅 */
.hero-section {
  height: 80vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  text-align: center;
  padding: 0 2rem;
}

.hero-content {
  max-width: 800px;
}

.hero-title {
  font-size: 4rem;
  font-weight: 700;
  margin-bottom: 1rem;
  background: linear-gradient(to right, #4a8cff, #83a4d4);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -1px;
}

.hero-subtitle {
  font-size: 1.5rem;
  margin-bottom: 2rem;
  color: #5e6c84;
}

/* 功能区域 */
.features-section {
  padding: 5rem 2rem;
  background-color: #ffffff;
}

.section-title {
  text-align: center;
  font-size: 2.5rem;
  font-weight: 600;
  margin-bottom: 3rem;
  color: #2c3e50;
}

.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 2rem;
  max-width: 1200px;
  margin: 0 auto;
}

.feature-card {
  background-color: #ffffff;
  border-radius: 12px;
  padding: 2rem;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.05);
  transition: transform 0.3s ease, opacity 0.3s ease;
  opacity: 0;
  transform: translateY(20px);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.feature-card.visible {
  opacity: 1;
  transform: translateY(0);
}

.feature-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1);
}

.feature-icon {
  font-size: 2.5rem;
  margin-bottom: 1.5rem;
  color: #409eff;
  opacity: 0.9;
}

.feature-title {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: #2c3e50;
}

.feature-description {
  color: #5e6c84;
  margin-bottom: 1.5rem;
  flex-grow: 1;
}

.feature-link {
  text-decoration: none;
}

/* 平台优势 */
.benefits-section {
  padding: 5rem 2rem;
  background-color: #f8f9fa;
}

.benefits-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(500px, 1fr));
  gap: 2rem;
  max-width: 1200px;
  margin: 0 auto;
}

.benefit-card {
  display: flex;
  background-color: #ffffff;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.05);
  transition: transform 0.3s ease, opacity 0.3s ease, box-shadow 0.3s ease;
  opacity: 0;
  transform: translateY(20px);
}

.benefit-card.visible {
  opacity: 1;
  transform: translateY(0);
}

.benefit-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1);
}

.benefit-image {
  flex: 0 0 40%;
  overflow: hidden;
}

.benefit-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.benefit-card:hover .benefit-image img {
  transform: scale(1.05);
}

.benefit-content {
  flex: 1;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.benefit-title {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: #2c3e50;
}

.benefit-description {
  color: #5e6c84;
  line-height: 1.6;
}

/* 项目进展 */
.progress-section {
  padding: 5rem 2rem;
  background-color: #ffffff;
}

.version-info {
  text-align: center;
  margin-bottom: 3rem;
}

.version-badge {
  display: inline-block;
  background-color: #409eff;
  opacity: 0.8;
  color: white;
  padding: 0.5rem 1rem;
  border-radius: 20px;
  font-weight: 600;
  margin-bottom: 1rem;
}

.version-title {
  font-size: 1.8rem;
  color: #2c3e50;
}

.timeline {
  max-width: 800px;
  margin: 0 auto 3rem;
  position: relative;
}

.timeline::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 20px;
  width: 2px;
  background-color: #e0e6ed;
}

.milestone-item {
  position: relative;
  padding-left: 50px;
  margin-bottom: 2.5rem;
  opacity: 0;
  transform: translateX(20px);
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.milestone-item.visible {
  opacity: 1;
  transform: translateX(0);
}

.milestone-dot {
  position: absolute;
  left: 11px;
  top: 5px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background-color: #e0e6ed;
  border: 2px solid #ffffff;
  z-index: 1;
}

.milestone-item.completed .milestone-dot {
  background-color: #409eff;
  opacity: 0.8;
}

.milestone-title {
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: #2c3e50;
}

.milestone-description {
  color: #5e6c84;
  margin-bottom: 0.5rem;
}

.milestone-date {
  font-size: 0.9rem;
  color: #8492a6;
}

.cta-container {
  text-align: center;
  margin-top: 3rem;
}

/* 响应式调整 */
@media (max-width: 768px) {
  .hero-title {
    font-size: 3rem;
  }

  .hero-subtitle {
    font-size: 1.2rem;
  }

  .section-title {
    font-size: 2rem;
  }

  .feature-card {
    padding: 1.5rem;
  }
  
  .benefits-grid {
    grid-template-columns: 1fr;
  }
  
  .benefit-card {
    flex-direction: column;
  }
  
  .benefit-image {
    flex: 0 0 200px;
  }
}
</style>
